{extend name="main" /}

{block name="body"}
{include file="breadcrumb" /}
<div class="layui-fluid">
    <table class="layui-table" style="margin-top: 0;">
        <tr>
            <th><b>用户名</b></th>
            <th><b>用户组</b></th>
            <th><b>状态</b></th>
            <th style="padding: 0 15px;line-height: 40px;"><b>操作</b> <span style="float: right"><a href="{:url('add')}" data-width="600px" data-height="450px" class="layui-btn layui-btn-sm xn_open" title="添加管理员">添加管理员</a></span> </th>
        </tr>

        <tbody>
        {foreach name="list" item="vo"}
        <tr>
            <td>{$vo.username}</td>
            <td>
                {foreach name="vo.auth_group_access" item="v"}
                <span class="layui-badge layui-bg-orange">{$v.title}</span>
                {/foreach}
            </td>
            <td class="layui-form">
                <input type="checkbox" lay-verify="required" lay-filter="status" name="status" data-id="{$vo.id}"
                       lay-skin="switch" lay-text="正常|禁止" value="1" {if condition="$vo['status'] eq 1"}checked{/if} >
            </td>
            <td>
                <a href="{:url('edit',array('id'=>$vo['id']))}" data-width="600px" data-height="450px" title="修改用户信息" class="layui-btn layui-btn-normal layui-btn-xs xn_open">
                    <i class="layui-icon layui-icon-edit"></i>修改
                </a>
                {if condition="$vo['id'] neq 1"}
                <a href="{:Url('delete',array('id'=>$vo['id']))}" title="确认要删除【{$vo.username}】吗？" class="layui-btn layui-btn-danger layui-btn-xs xn_delete">
                    <i class="layui-icon layui-icon-delete"></i>删除
                </a>
                {/if}
            </td>
        </tr>
        {/foreach}
        </tbody>
    </table>
</div>
{/block}

{block name="js"}
<script>
    layui.form.on('switch(status)', function(data){
        //layer.tips('开关checked：'+ (this.checked ? 'true' : 'false'), data.othis)
        var val = this.checked ? 1 : 0;
        var id = $(this).attr('data-id');
        var url = "{:url('edit')}";
        $.post(url,{id:id,status:val},function (res) {
            console.log(res);
            layer.tips(res.msg, data.othis);
        },'json')
    });
</script>
{/block}